import { createStore } from 'vuex'
import stateObj from './state'
import { isObject } from '@/utils/utils';

export default createStore ({
  state: {
    ...stateObj
  },
  //同步的状态管理
  mutations: {
    setStore: function (state, payload) {
      const keys = Object.keys(payload);
      keys.forEach(item => {
        if (isObject(payload[item])) {
          state[item] = Object.assign({}, state[item], payload[item])
        } else {
          state[item] = payload[item]
        }
      })
    },
    /**
     * 清除指定值的状态
     * @param {*} state
     * @param {*} key //需要清除的key
     * @param {*} value //清除后的结果
     */
     clearStateByKey(state, { key, value }) {
      state[key] = value;
    },
  },
  //异步的状态管理
  actions: {

  },
  //计算属性
  getters: {

  },
  setters: {

  },
  //按模块的状态管理
  modules: {

  }
})

// import { createStore } from 'vuex'

// export const store = createStore({
//   state () {
//     return {
//       count: 1
//     }
//   }
// })